<template>
  <div class="item">
    <div class="label">{{ label }}</div>
    <div class="check">
      <p v-for="(item, index) in data"
         :key="item.id"
         :class="{active: modelValue === index}"
         class="ellipsis"
         @click="emits('update:modelValue', index);emits('change');">
        {{ item.name }}
      </p>
    </div>
  </div>
</template>

<script lang="ts"
        setup>
import type {IdName} from '@/types/common'

defineProps<{
  modelValue: number
  label: string
  data: IdName[]
}>()

let emits = defineEmits<{
  (eventName: 'update:modelValue', value: number): void
  (eventName: 'change'): void
}>()
</script>

<style lang="less"
       scoped>
.item {
  display: flex;
  line-height: 40px;

  .label {
    width: 80px;
    height: 40px;
    display: flex;
    align-items: center;
    color: #999999;
  }

  .check {
    flex: 1;
    display: flex;
    flex-wrap: wrap;

    p {
      cursor: pointer;
      margin-right: 36px;
      max-width: 112px;

      &:hover, &.active {
        color: @xtxColor;
      }
    }
  }
}
</style>